#!/bin/bash

set -e
tools_path=/mnt/ilustre/app/medical/tools
data_path=/mnt/ilustre/app/medical/.data

source $tools_path/.var


log=.log
if [ ! -e "$log" ]; then
	:> $log
fi

###--------------- tools path ---------------###

script_path=${tools_path}/script/
bwa=${tools_path}/bwa-0.7.12/bwa
# bwa=/share/apps/bwa-0.7.5a/bwa
samtools=${tools_path}/samtools-1.2/samtools
picard_path=${tools_path}/picard-tools-1.119/
gatk_path=${tools_path}/GenomeAnalysisTK-1.6-9-g47df7bb/
gatk3_path=${tools_path}
gatk=${gatk3_path}/GenomeAnalysisTK.jar
snpeff_path=${tools_path}/snpEff
snpeff=${snpeff_path}/snpEff.jar
snpsift=${snpeff_path}/SnpSift.jar
bcftools=${tools_path}/bcftools-1.2/bcftools
bgzip=${tools_path}/htslib-1.2.1/bgzip
tabix=${tools_path}/htslib-1.2.1/tabix
fastuniq=${tools_path}/FastUniq/fastuniq
###--------------- end tools path ---------------###


vcftools_path=${tools_path}/vcftools_0.1.12b/bin

fp_path=${data_path}/vcf/fp_qiagen



# cat XPanelsBlackListCompleteAllFPs.vcf \
# |awk 'BEGIN{print "#CHR\tFROM\tTO\tREF\tALT\tFILTER"}{print $1"\t"$2"\t"$2"\t"$4"\t"$5"\t"$7}' \
# |sed -e 's/^chr//' \
# > XPanelsBlackListCompleteAllFPs.anno.b37.txt

# bgzip -c XPanelsBlackListCompleteAllFPs.anno.b37.txt > XPanelsBlackListCompleteAllFPs.anno.b37.txt.gz
# tabix -b 2 -e 3 XPanelsBlackListCompleteAllFPs.anno.b37.txt.gz

s1=`basename $1 .vcf` 2>>$log


echo $0 input.vcf output.vcf |tee -a $log

echo 2>>$log 1>&2
echo 2>>$log 1>&2
echo vcftools vcf-annotate 2>>$log 1>&2

cat $1 \
| $vcftools_path/vcf-annotate \
-a $fp_path/XPanelsBlackListCompleteAllFPs.anno.b37.txt.gz \
-d $fp_path/des.txt \
-c CHROM,FROM,TO,REF,ALT,FILTER \
> $s1.fp.vcf \
2>>$log


if [ -n "$2" -a "$s1.fp.vcf" != "$2" ]; then
	mv $s1.fp.vcf $2 2>>$log
fi
